<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工程案例</title>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/ueditor.all.min.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
    <link rel="stylesheet" href="/static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/css/layui.css">
    <script src="/static/layuiAdmin.std-v1.7.1/src/layuiadmin/layui/layui.js"></script>
    <style>
        .layui-form-selected dl {
            z-index: 1000;
        }
    </style>
</head>

<body>
    <?php
    include "../../fun.php";
    isLogin();
    $db=conndb();
    $id=$_GET["id"];
    $sql="select * from cases where id='{$id}'";
    $res=query1($db, $sql, false);
    ?>
    <div style="padding-top:10px">
        <form class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">类别</label>
                <div class="layui-input-block" style="width:200px">
                    <?php echo select_trees(8, $db, $res["sortid"], "sortid") ?>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block" style="width:500px">
                    <input type="text" name="cases_name" required lay-verify="required" placeholder="请输入标题"
                        autocomplete="off" class="layui-input"
                        value="<?php echo $res["cases_name"]; ?>">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图片</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="pic">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <!-- 存放图片名称 -->
                    <input type="hidden" name="pic"
                        value="<?php echo $res["pic"] ?>">
                    <!-- 展示图片 -->
                    <!-- 设置img的样式 -->
                    <style>
                        img {
                            max-width: 100px;
                        }
                    </style>
                    <div id="picInfo" style="display:inline-block"></div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <script id="editor" name="content" type="text/plain" style="width:1024px;height:500px;">
                        <?php echo $res["content"]; ?>
                    </script>
                    <script>
                        UE.getEditor('editor');
                    </script>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">添加时间</label>
                <div class="layui-input-block" style="width:500px">
                    <!-- date("Y-m-d H:i:s") 获取当前时间并格式化 -->
                    <input type="text" class="layui-input" name="time" id="time"
                        value="<?php echo date("Y-m-d H:i:s", $res["time"]); ?>">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="hidden" name="id"
                    value="<?php echo $id;?>">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
                    value="确认添加">
                <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
                    value="确认编辑">
            </div>
        </form>
    </div>

    <script>
        layui.use(['upload','laydate'], function() {
            var upload = layui.upload,
                $ = layui.$,
                laydate = layui.laydate;

            //执行实例
            upload.render({
                elem: '#pic', //绑定元素
                url: '../upload.php', //上传接口
                done: function(res) {
                    //上传完毕回调
                    if (res.code == 0) {
                        $("input[name='pic']").val(res.pic);
                        var html = `<img src="/admin/upload/${res.pic}" alt="">`;
                        $("#picInfo").html(html);
                    }
                },
                error: function() {
                    //请求异常回调
                }
            });

            //日期时间范围选择
            laydate.render({
                elem: '#time',
                type: 'datetime'
            });
        });
    </script>
</body>

</html>